<?php declare(strict_types=1);


namespace Database\Migration;

use Swoft\Devtool\Annotation\Mapping\Migration;
use Swoft\Devtool\Migration\Migration as BaseMigration;

/**
 * 账户模型
 * 
 * Class AccountUser
 * 
 * @since 2.0
 *
 * @Migration(time=20210713074618)
 */
class AccountUser extends BaseMigration
{
    /**
     * @return void
     */
    public function up(): void
    {
        $sql = <<<sql
CREATE TABLE `account_user` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '账号id',
    `email` varchar(30) NOT NULL DEFAULT '' COMMENT '邮箱',
    `phone` varchar(15) NOT NULL DEFAULT '' COMMENT '手机号',
    `username` varchar(30) NOT NULL DEFAULT '' COMMENT '用户名',
    `password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码',
    `create_at` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
    `create_ip_at` varchar(12) NOT NULL DEFAULT '' COMMENT '创建ip',
    `last_login_at` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次登录时间',
    `last_login_ip_at` varchar(12) NOT NULL DEFAULT '' COMMENT '最后一次登录ip',
    `login_times` int(11) NOT NULL DEFAULT '0' COMMENT '登录次数',
    `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态 1:enable, 0:disable, -1:deleted',
    PRIMARY KEY (`id`),
    KEY `idx_email` (`email`),
    KEY `idx_phone` (`phone`),
    KEY `idx_username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账户';
sql;
        $this->execute($sql);
    }

    /**
     * @return void
     */
    public function down(): void
    {
        $dropSql = <<<sql
drop table if exists `account_user`;
sql;
        $this->execute($dropSql);
    }
}
